package com.alpha.tests;

import static org.junit.Assert.assertEquals;

import java.util.TreeMap;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.alpha.bom.Answer;
import com.alpha.bom.ExamResponse;
import com.alpha.bom.PracticeExam;
import com.alpha.bom.Question;
import com.alpha.bom.RealExam;
import com.alpha.bom.Student;

public class ExamResponseTest {
	private Answer answer;
	private Question question;
	private ExamResponse practiceER;
	private ExamResponse realER;
	
	@Before
	public void setUp() throws Exception {
		RealExam realExam = new RealExam(1001);
		PracticeExam practiceExam = new PracticeExam(1002, "Practice Exam");
		Student student = new Student(1001);
		this.realER = new ExamResponse(practiceExam, student);
		this.practiceER = new ExamResponse(realExam, student);
		
		//for testComputeScore()
		//0-9 correct answers
		//10-19 wrong answers
		//20-14 null answers
		for(int i=0; i<10; i++){
			this.answer =  new Answer(i, "correct"+i);
			this.question = new Question(i, "type", "", answer, "topic");
			if(i>=20) answer = null;
			else if(i>=10) answer =  new Answer(i+1, "worng"+i);
			this.realER.addAnswer(this.question, this.answer);
			this.practiceER.addAnswer(this.question, this.answer);
		}
		
		//for testAddAnswer()
		this.answer =  new Answer(1001, "correct");
		this.question = new Question(1001, "type", "", answer, "topic");
	}

	@After
	public void tearDown() throws Exception {
		this.practiceER = null;
		this.realER = null;
		this.question = null;
		this.answer = null;
	}

	@Test
	public void testAddAnswer() {
		assertEquals("Adding new Answer to Practice Exam Response", true, practiceER.addAnswer(this.question, this.answer));
		assertEquals("Adding new Answer to Real Exam Response", true, realER.addAnswer(this.question, this.answer));
		
		
	}

	@Test
	public void testComputeScore() {
		assertEquals("Testing Compute Score to Practice Exam", 10, practiceER.computeScore());
		assertEquals("Testing Compute Score to Real Exam", 10, realER.computeScore());
	}

}
